package com.spzx.user.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.user.api.RemoteUserInfoService;
import com.spzx.user.api.domain.UserAddress;
import com.spzx.user.api.domain.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RemoteUserInfoServiceFallbackFactory implements FallbackFactory<RemoteUserInfoService> {


    @Override
    public RemoteUserInfoService create(Throwable cause) {
        log.error("用户服务调用失败:{}", cause.getMessage());
        return new RemoteUserInfoService() {


            @Override
            public R<Boolean> register(UserInfo userInfo) {
                return R.fail("用户注册失败:" + cause.getMessage());
            }

            @Override
            public R<UserInfo> login(String username, String password) {

                return R.fail("用户登录失败:" + cause.getMessage());
            }

            @Override
            public R<UserAddress> getInfo(Long id) {
                return R.fail("查询用户收获地址详情失败:" + cause.getMessage());
            }
        };

    }
}
